<template>
	<block v-if="type==1">
		<view class="order_item_container bc_fff br_8 plr_12">
			<view class="height_44 fx aic jcb bob_1 boc_grey">
				<view class="">
					{{data.createTime||''}}
				</view>
				<view class="fc_primary">
					{{data.orderStatusStr||''}}
				</view>
			</view>
			<view class="pb_12 bob_1 boc_grey flow_h">
				<view class="fx fx_nw"
					v-if="!data.orderInfoList||!data.orderInfoList.length||data.orderInfoList.length===1">
					<CustomImage width="160rpx" height="160rpx" radius="8rpx"
						:src="getStaticUrl((data.orderInfoList && data.orderInfoList[0])?data.orderInfoList[0].image:data.image)">
					</CustomImage>
					<view class="ml_12 fx_1 flow_h" v-if="data.orderInfoList && data.orderInfoList[0]">
						<view class="fe">
							{{data.orderInfoList[0].productName||''}}
						</view>
						<view class="mt_4 fc_999 height_17 lh_17">
							{{productRuleStr(data.orderInfoList[0].productRule)||''}}
						</view>
						<view class="mt_4 fc_999">
							×{{data.orderInfoList[0].payNum||0}} 
						</view>
						<view class="mt_16 fx fx_nw aic jcb">
							<view class="fc_primary">
								¥{{productAmount(data.orderInfoList[0])||0}}
							</view>
							
							<view class="fz_16 fb group_btn_right" v-if="data.orderType==7">
								积分抽奖
							</view>
						</view>
						
						
					</view>
					<view class="ml_12 fx_1 flow_h" v-else>
						<view class="fe">
							{{data.productName||''}}
						</view>
						<view class="mt_4 fc_999 height_17 lh_17">
							{{data.productRuleStr||''}}
						</view>
						<view class="mt_4 fc_999">
							×{{data.productCount||data.payNum||0}}
						</view>
						<view class="fz_16 fb">
							¥{{productAmount(data)||0}}
						</view>
					</view>
				</view>
				<view class="fx pt_12 fx_nw flow_x" v-else-if="data.orderInfoList">
					<view class="img_wrap pr" v-for="item,index in data.orderInfoList" :key="index">
						<view class="badge">
							<u-badge numberType="limit" bgColor="#FE0000" max="99" :value="item.payNum"
								v-if="item.payNum"></u-badge>
						</view>
						<CustomImage width="160rpx" height="160rpx" radius="8rpx" :src="getStaticUrl(item.image)">
						</CustomImage>
					</view>
				</view>
				<view class="mt_16 fx fx_nw aic jcb">
					<view class="fc_primary">
						{{getOrderType}}
					</view>
					<view>
						共{{data.productCount||0}}件商品 总金额
						<text class="ml_8 fc_zhured">￥{{data.payAmount || 0}}</text>
					</view>
				</view>
			</view>
			<view class="ptb_8 fx fx_w jce grid_8">
				<button class="custom_btn default lh_28 plr_12 br_18 fz_14" @click="$emit('cancel',data)"
					v-if="$permisList(data.orderStatus,'取消下单', !isSingleDetail)">取消下单</button>
				<button class="custom_btn default lh_28 plr_12 br_18 fz_14" @click="handleDetail">查看详情</button>
				<button class="custom_btn primary lh_28 plr_12 br_18 fz_14" @click="$emit('confirm',data)"
					v-if="$permisList(data.orderStatus,'确认下单',appType==base.ADMIN_TYPE)">确认下单</button>
				<button class="custom_btn primary lh_28 plr_12 br_18 fz_14" @click="handleUploadPayment"
					v-if="$permisList(data.orderStatus,'上传支付凭证')">上传支付凭证</button>
				<button class="custom_btn primary lh_28 plr_12 br_18 fz_14" @click="handleUploadPayment"
					v-if="$permisList(data.orderStatus,'上传尾款凭证')">上传尾款凭证</button>
				<button class="custom_btn primary lh_28 plr_12 br_18 fz_14" @click="$emit('confirm',data, 'goods')"
					v-if="$permisList(data.orderStatus,'确认收货', !isSingleDetail)">确认收货</button>
				<button class="custom_btn primary lh_28 plr_12 br_18 fz_14" @click="$emit('confirm',data, 'install')"
					v-if="$permisList(data.orderStatus,'确认安装', !isSingleDetail)">确认安装</button>
				<button class="custom_btn default lh_28 plr_12 br_18 fz_14" @click="$emit('delete',data)"
					v-if="$permisList(data.orderStatus,'删除记录')">删除记录</button>
			</view>
		</view>
	</block>
	<block v-else-if="type==3">
		<view class="order_item_container bc_fff br_8 plr_12">
			<view class="height_44 fx aic jcb bob_1 boc_grey">
				<view class="fx fx_nw">
					{{data.createTime||''}}
					<text class="fc_primary ml_4" v-if="data.deliveryWay==1">自提</text>
				</view>
				<view class="fc_primary">
					{{data.orderStatusStr||''}}
				</view>
			</view>
			<view class="pb_12 bob_1 boc_grey flow_h">
				<view class="fx fx_nw" v-if="!data.orderInfoList||!data.orderInfoList.length">
					<CustomImage width="160rpx" height="160rpx" radius="8rpx" :src="getStaticUrl(data.image)">
					</CustomImage>
					<view class="ml_12 fx_1 flow_h">
						<view class="fe">
							{{data.productName||''}}
						</view>
						<view class="mt_4 fc_999 height_17 lh_17">
							{{data.productRuleStr||''}}
						</view>
						<view class="mt_4 fc_999">
							×{{data.productCount||0}}
						</view>
						<view class="fz_16 fb">
							¥{{productAmount(data)||0}}
						</view>
					</view>
				</view>
				<view class="fx pt_12 fx_nw flow_x" v-else-if="data.orderInfoList">
					<view class="img_wrap pr" v-for="item,index in data.orderInfoList" :key="index">
						<view class="badge">
							<u-badge numberType="limit" bgColor="#FE0000" max="99" :value="item.payNum"
								v-if="item.payNum"></u-badge>
						</view>
						<CustomImage width="160rpx" height="160rpx" radius="8rpx" :src="getStaticUrl(item.image)">
						</CustomImage>
					</view>
				</view>
				<view class="mt_16 fx fx_nw aic jcb">
					<view class="fx aic">
						<CustomImage width="60rpx" height="60rpx" radius="30rpx" :src="getStaticUrl(item.image)">
						</CustomImage>
						<text class="ml_8">{{item.orderUser||''}}</text>
						<text class="ml_8" v-if="userType!=1">{{item.salesName||''}}</text>
					</view>
					<view>
						共{{data.productCount||0}}件商品 总金额
						<text class="ml_8 fc_zhured">￥{{data.payAmount||0}}</text>
					</view>
				</view>
			</view>
			<view class="ptb_8 fx fx_w jce grid_8">
				<button class="custom_btn default lh_28 plr_12 br_18 fz_14" @click="$emit('cancel',data)"
					v-if="$permisList(data.orderStatus,'取消下单', !isSingleDetail)">取消下单</button>
				<button class="custom_btn default lh_28 plr_12 br_18 fz_14" @click="handleDetail">查看详情</button>
				<button class="custom_btn primary lh_28 plr_12 br_18 fz_14" @click="handleUploadPayment"
					v-if="$permisList(data.orderStatus,'上传支付凭证')">上传支付凭证</button>
				<button class="custom_btn primary lh_28 plr_12 br_18 fz_14" @click="handleUploadPayment"
					v-if="$permisList(data.orderStatus,'上传尾款凭证')">上传尾款凭证</button>
				<button class="custom_btn primary lh_28 plr_12 br_18 fz_14" @click="$emit('confirm',data)"
					v-if="$permisList(data.orderStatus,'确认下单')">确认下单</button>
				<button class="custom_btn primary lh_28 plr_12 br_18 fz_14" @click="$emit('confirm',data, 'goods')"
					v-if="$permisList(data.orderStatus,'确认收货', !isSingleDetail)">确认收货</button>
				<button class="custom_btn primary lh_28 plr_12 br_18 fz_14" @click="$emit('confirm',data, 'install')"
					v-if="$permisList(data.orderStatus,'确认安装', !isSingleDetail)">确认安装</button>
				<button class="custom_btn default lh_28 plr_12 br_18 fz_14" @click="$emit('delete',data)"
					v-if="$permisList(data.orderStatus,'删除记录')">删除记录</button>
			</view>
		</view>
	</block>
	<block v-else>
		<view class="order_item_container pt_12 bc_fff">
			<view class="fx fx_nw pr">
				<CustomImage width="160rpx" height="160rpx" radius="8rpx" :src="getStaticUrl(data.image)">
				</CustomImage>
				<view class="ml_12 fx_1 flow_h" v-if="userType==9">
					<view class="fe_2 height_34 lh_17">
						{{data.productName||''}}
					</view>
					<view class="mt_4 fc_999 height_17 lh_17 fx fx_nw jcb">
						<text>{{productRuleStr(data.productRule||'')}}</text>
						<text>×{{data.productCount||data.payNum||0}}</text>
					</view>
				</view>
				<view class="ml_12 fx_1 flow_h" v-else>
					<view class="fe">
						{{data.productName||''}}
					</view>
					<view class="mt_4 fc_999 height_17 lh_17">
						{{productRuleStr(data.productRule)}} ×{{data.payNum||0}}
					</view>
					<view class="mt_4 fc_999 height_17 lh_17 fx grid_8">
						<text v-if="data.deliveryCost">配送费<text class="fc_333">{{data.deliveryCost ? ('￥'+data.deliveryCost): (orderData.preOrderType == 5 ? '包邮' : '以线下门店为准')}}</text></text>
						<text v-if="data.upstairsCost">上楼费<text
								class="fc_333">{{data.upstairsCost ? ('￥'+data.upstairsCost): (orderData.preOrderType == 5 ? '包邮' : '以线下门店为准')}}</text></text><text v-if="orderData.isInstall">
							安装费<text class="fc_333">{{data.installCost ? ('￥'+data.installCost): (orderData.preOrderType == 5 ? '包邮' : '以线下门店为准')}}</text></text>
					</view>
					<view class="fz_14 fb fc_zhured" v-if="orderData.orderType==6">
						<text class="fb fc_zhured">{{data.integral||0}}积分</text>
						<text class="fz_10 pb_10">+ ¥</text>
						<text class="fb fc_zhured">{{data.price||0}}</text>
					</view>
					<view class="fz_16 fb fc_zhured" v-else>
						¥{{salePrice||0}}
					</view>
				</view>
				<image v-if="data.orderStatus==13" class="pa r_2 b_0 width_56 height_56" src="../../../static/images/cancel_order.png" mode=""></image>
			</view>
			<view class="ptb_8 fx fx_w jce grid_8">
				<button class="custom_btn default lh_28 plr_12 br_18 fz_14" @click="$emit('cancel',data)"
					v-if="$permis(data.orderStatus,'取消订单',!isSingleDetail)">取消下单</button>
				<button class="custom_btn default minw_78 lh_28 plr_12 br_40 fz_14"
					v-if="$permis(data.orderStatus,'评价', orderType == 1)&&orderData.orderType!=6"
					@click="$emit('evaluate',data)">{{data.isReply==1?'查看评价':'评价'}}</button>
				<button class="custom_btn default minw_78 lh_28 plr_12 br_40 fz_14"
					v-if="$permis(data.orderStatus,'售后', orderType == 1)&&orderData.orderType!=6"
					@click="$emit('aftersale',data)">{{data.afterSaleId?'查看售后':'售后'}}</button>
				<button class="custom_btn default lh_28 plr_12 br_18 fz_14" @click="$emit('upload',data)"
					v-if="$permis(data.orderStatus,'上传物流单',!isSingleDetail&&!data.logisticsImageUrl)&&((userType==2&&orderData.deliveryWay==1)||userType!=2)">上传物流单</button>
				<button class="custom_btn default lh_28 plr_12 br_18 fz_14" @click="$emit('check',data)"
					v-if="$permis(data.orderStatus,'查看物流单',data.logisticsImageUrl)">查看物流单</button>
				<button class="custom_btn default lh_28 plr_12 br_18 fz_14" @click="$emit('confirm','goods',data.orderInfoId)"
					v-if="$permis(data.orderStatus,'确认收货',!isSingleDetail)">确认收货</button>
				<button class="custom_btn primary lh_28 plr_12 br_18 fz_14" @click="$emit('confirm','install',data.orderInfoId)"
					v-if="$permis(data.orderStatus,'确认安装',!isSingleDetail)">确认安装</button>
			</view>
		</view>
	</block>
</template>

<script>
	import CustomImage from '@/components/Image'
	import api from '@/service/config/api.js'
	import {
		mapState,
		mapGetters
	} from 'vuex'
	import {
		getStaticUrl
	} from '@/utils/index.js'
	import {
		BASE
	} from '@/const/base.js'
	export default {
		components: {
			CustomImage,
		},
		props: {
			// 1-我的订单 3-雷达订单
			type: {
				type: String | Number,
				default: 1
			},
			orderType: {
				type: String | Number,
				default: 1
			},
			goodsType: {
				type: String | Number,
				default: 1
			},
			data: {
				type: Object,
				default: () => ({})
			},
			orderData: {
				type: Object,
				default: () => ({})
			},
			isSingleDetail: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				base: BASE,
			};
		},
		computed: {
			...mapState(['userType', 'appType']),
			...mapGetters(['isVip']),
			productRuleStr() {
				return data => {
					console.log('data---', data)
					return data ? JSON.parse(data).map(item1 => item1.value).join(' ') : ''
				}
			},
			getStaticUrl() {
				return (src) => getStaticUrl(src)
			},
			getOrderType() {
				// 1-普通订单，2-秒杀订单，3-砍价订单，4-抢购订单，5-拼团订单，6-积分订单
				if (this.data.orderStatus == 2 && this.data.auditPass == false) {
					return '审核拒绝'
				}
				switch (this.data.orderType) {
					case 2:
						return '秒杀订单'
					case 3:
						return '砍价订单'
					case 4:
						return '抢购订单'
					case 5:
						return '拼团订单'
					case 6:
						return '积分订单'
					default:
						return ''
						break
				}
			},
			salePrice() {
				if (this.data.orderType && this.data.orderType > 1 && this.data.orderType < 6) {
					return this.data.afterDiscountAmount || this.data.price || 0
				}
				if (this.goodsType && this.goodsType > 1 && this.goodsType < 6) {
					return this.data.afterDiscountAmount || this.data.price || 0
				}
				return this.appType === this.$base.USER_TYPE ? (this.data.price || 0) : (this.data.purchasingPrice ||
					this.data.price || 0)
			},
			productAmount() {
				return item => {
					if (this.data.orderType && this.data.orderType > 1 && this.data.orderType < 6) {
						return item.afterDiscountAmount || item.price || 0
					}
					if (this.goodsType && this.goodsType > 1 && this.goodsType < 6) {
						return item.afterDiscountAmount || item.price || 0
					}
					return this.appType === this.$base.USER_TYPE ? this.isVip ? item.afterDiscountAmount : (item.productAmount || 0) : (item.purchasingPrice ||
						item.productAmount || 0)
				}
			},
			// 是否单商品
			isSingle() {
				return dataItem => {
					if (dataItem.orderInfoList && dataItem.orderInfoList.length) {
						let count = dataItem.orderInfoList.length
						return count <= 1 ? true : dataItem.isSendTogether
					} else if (dataItem.orderBrandInfoList && dataItem.orderBrandInfoList.length) {
						let count = dataItem.orderBrandInfoList.reduce((num, item) => {
							return num + item.productInfoList.length
						}, 0)
						return count <= 1 ? true : dataItem.isSendTogether
					} else {
						return true
					}
				}
			}
		},
		methods: {
			handleDetail() {
				if (this.data.id) {
					uni.navigateTo({
						url: `/pages/person/pages/order_detail?id=${this.data.id}&type=${this.type}`
					})
					// uni.navigateTo({
					// 	url: '/pages/person/pages/evaluate?o_id=' + this.data.id
					// })
				}
			},
			// 上传支付凭证
			handleUploadPayment() {
				if (this.data.id) {
					let payAmount = null
					let certificateType = 1
					if (this.data.payType == 1) {
						payAmount = this.data.payAmount
					} else {
						if (this.data.orderStatus == 5) {
							payAmount = this.data.waitPayDeposit
						} else {
							payAmount = this.data.waitPayFinal
						}
					}
					console.log('this.data.payType',this.data.payType,this.data.orderStatus)
					if (this.data.payType == 1) {
						if (this.data.orderStatus == 5) {
							certificateType = 3
						} else {
							certificateType = 2
						}
					} else {
						if (this.data.orderStatus == 5)
							certificateType = 1
						if (this.data.orderStatus == 8||this.data.orderStatus == 10)
							certificateType = 2
					}

					uni.navigateTo({
						url: `/pages/person/pages/upload?id=${this.data.id}&payType=${this.data.payType}&type=payment&certificateType=${certificateType}&payAmount=${payAmount||0}`
					})
				}
			},
			handleEvaluate() {
				uni.navigateTo({
					url: '/pages/person/pages/evaluate?o_id=' + this.data.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.img_wrap+.img_wrap {
		margin-left: 24rpx;
	}
	.group_btn_right {
		background: url('~@/static/images/btn1.png');
		background-size: 100% 100%;
		padding: 10rpx;
		text-align: center;
		color: #ffffff;
		font-size: 18rpx;
		width: 120rpx;
	}
	.badge {
		position: absolute;
		top: -12rpx;
		right: -12rpx;
		z-index: 2;
	}
</style>